const sendCode = {
	data() {
		return {
			sendCode: false, //验证码
			times: 60,
		}
	},
	methods: {
		//获取验证码
		sendTextCode(mobile) {
			if (mobile) {
				let judge = this.isMobile(mobile)
				if (judge) {
					uni.showToast({
						title:'已发送至'+mobile+'~',
						icon:'success'
					})
					this.sendCode = true
					this.timer = setInterval(() => {
						if (this.times > 0 && this.times <= 60) {
							this.times--
						} else {
							this.sendCode = false
							clearInterval(this.timer)
						}
					}, 1000)
				} else {
					uni.showToast({
						title:'请填写正确手机号！',
						icon:'none',
					})
					return
				}
			} else {
				uni.showToast({
					title:'请填先输入手机号！',
					icon:'none',
				})
				return
			}
		},
		//消息失败
		showFalse() {
			uni.showToast({
				title:'60s内不能重复发送！',
				icon:'none',
			})
		},

		/**
		 * 验证手机格式
		 */
		isMobile(value) {
			return /^1[3-9]\d{9}$/.test(value)
		}
	}
}

export default sendCode
